package com.kun.service.util;

import com.kun.domain.TRolePermission;
import com.kun.domain.TUser;

import java.util.List;

public class UserContext {

    private static final ThreadLocal<TUser> T_USER_THREAD_LOCAL = new ThreadLocal<>();

    public static void setUser(TUser user) {
        T_USER_THREAD_LOCAL.set(user);
    }

    public static TUser getUser() {
        return T_USER_THREAD_LOCAL.get();
    }

    public static void clear() {
        T_USER_THREAD_LOCAL.remove();
    }

    public static Long getUserId() {
        return getUser().getId();
    }

    /**
     * 获取用户权限
     */
    public static List<TRolePermission> getUserPermission() {
        return getUser().getUserInfo().getPermissions();
    }
}
